package com.guanyong.admin.controllers.api;

import com.guanyong.admin.config.VideoLocalUtil;
import com.guanyong.admin.handle.GlobleData;
import com.guanyong.admin.handle.UploadFileType;
import com.guanyong.constant.VideoConstant;
import com.guanyong.model.*;
import com.guanyong.services.*;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import com.guanyong.utils.Comm.VideoTypeUtils;
import com.guanyong.utils.NetUtils.UploadFileUtil;
import com.guanyong.utils.UniqueID.DBObjectID;

import com.qiniu.common.Zone;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.util.Auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;

/**
 * Created by mxk on 2017/6/1.
 */
@RestController
@RequestMapping("/api/video/")
public class VideoApi {

    @Autowired
    FilmServices filmServices;

    @Autowired
    VideoScoreService videoScoreService;

    @Autowired
    VideoSourceService videoSourceService;

    @Autowired
    VideoTopLogService videoTopLogService;

    @Autowired
    VideoTodayService videoTodayService;

    @Autowired
    UploadFileUtil uploadFileUtil;

    @Autowired
    VideoLocalUtil videoLocalUtil;

    @Autowired
    GlobleData globleData;


    @RequestMapping(value = "getfilmlist", method = RequestMethod.GET)
    ResultObject<HashMap<String,Object>> getuserlist(HttpServletRequest request,
                                                     @RequestParam String filmtype ,
                                                     @RequestParam String  filmprice,
                                                     @RequestParam String name,
                                                     @RequestParam Integer state,
                                                     @RequestParam Integer years,
                                                     @RequestParam Integer country,
                                                     @RequestParam int pno,
                                                     @RequestParam int pagesize,
                                                     @RequestParam int allcount) {
        ResultObject<HashMap<String,Object>> result = new ResultObject<HashMap<String,Object>>();
        FilmModel filmModel=new FilmModel();
        filmModel.setfName(name);
        filmModel.setfCountry(country);
        filmModel.setfFilmtype(filmtype);
        filmModel.setfYear(years);
        filmModel.setfShow(state);
        if (filmprice!=null && !filmprice.equals("")){
            filmModel.setfPricetagid(filmprice);
        }
        HashMap<String,Object> hashMap=filmServices.GetFilmList(filmModel,pno, pagesize,allcount);
        result.setResult(hashMap);
        return result;
    }
    //updatefilmstate

    @RequestMapping(value = "updatefilmstate", method = RequestMethod.POST)
    ResultObject<Integer> updatefilmstate(HttpServletRequest request,
                                      @RequestParam String id ,
                                      @RequestParam Integer state ) {
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        FilmModel filmModel=new FilmModel();
        filmModel.setfId(id);
        filmModel.setfShow(state);
        Integer res=filmServices.UpdateFilmSingle(filmModel);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;
    }


    @RequestMapping(value = "addfilm", method = RequestMethod.POST)
    ResultObject<String> inserfilm(HttpServletRequest request,
                                    @RequestParam String film_name ,
                                    @RequestParam String film_keyword ,
                                    @RequestParam String film_price ,
                                    @RequestParam Integer film_year ,
                                    @RequestParam String film_showdate,
                                    @RequestParam Integer film_country ,
                                    @RequestParam String film_director ,
                                    @RequestParam String film_performer ,
                                    @RequestParam String film_filmtype ,
                                    @RequestParam String film_desc,
                                    @RequestParam String film_impression,
                                    @RequestParam double filmscore_douban,
                                    @RequestParam double filmscore_lanfanqie,
                                    @RequestParam double filmscore_imdb,
                                    @RequestParam Integer film_makesharect,
                                    @RequestParam Integer film_makelookct,
                                    @RequestParam Integer film_makegoodct,
                                    @RequestParam Integer film_makecollectct,
                                    @RequestParam Integer film_makeplayct,
                                    @RequestParam(value = "film_pic",required = false) MultipartFile film_pic,
                                    @RequestParam(value = "film_pic1",required = false) MultipartFile  film_pic1,
                                   @RequestParam(value = "film_pic2",required = false) MultipartFile  film_pic2) {
        ResultObject<String> resultObject=new ResultObject<String>();
        String path  ="";
        try {
            path = uploadFileUtil.SaveFileByMultiFlie(film_pic,request,UploadFileType.VideoPhoto);
            //path = uploadFileUtil.SaveStreamFile(UploadFileType.Photo, ".jpg", request);
        } catch (Exception e) {
            e.printStackTrace();
            path="";
        }
        String path1="";
        try {
            path1 = uploadFileUtil.SaveFileByMultiFlie(film_pic1,request,UploadFileType.VideoPhoto);
            //path = uploadFileUtil.SaveStreamFile(UploadFileType.Photo, ".jpg", request);
        } catch (Exception e) {
            e.printStackTrace();
            path1="";
        }
        String path2="";
        try {
            path2 = uploadFileUtil.SaveFileByMultiFlie(film_pic2,request,UploadFileType.VideoPhoto);
            //path = uploadFileUtil.SaveStreamFile(UploadFileType.Photo, ".jpg", request);
        } catch (Exception e) {
            e.printStackTrace();
            path2="";
        }



        FilmModel filmModel=new FilmModel();
        String newid = new DBObjectID().toString();
        filmModel.setfId(newid);
        filmModel.setfName(film_name);
        filmModel.setfKeyword(film_keyword);
        filmModel.setfPricetagid(film_price);
        filmModel.setfCountry(film_country);
        filmModel.setfYear(film_year);
        Date showdate=com.guanyong.utils.Comm.DateExt.StrToDate2(film_showdate);
        filmModel.setfShowtime(showdate);
        filmModel.setfDirector(film_director);
        filmModel.setfImpression(film_impression);
        filmModel.setfPerformer(film_performer);
        filmModel.setfFilmtype(film_filmtype);
        filmModel.setfVideotype(VideoTypeUtils.getViodeType(film_filmtype));
        filmModel.setfKeyword(film_keyword);
        filmModel.setfKeyword(film_keyword);
        filmModel.setfMakesharect(film_makesharect);
        filmModel.setfMakecollect(film_makecollectct);
        filmModel.setfMakelookct(film_makelookct);
        filmModel.setfMakegoodct(film_makegoodct);
        filmModel.setfMakepalyct(film_makeplayct);
        filmModel.setfPhoto(path);
        filmModel.setfPhotow(path1);
        filmModel.setfPhotos(path2);
        FilmInfoModel filmInfoModel=new FilmInfoModel();
        filmInfoModel.setfId(newid);
        filmInfoModel.setfIntroduce(film_desc);
        VideoScoreModel videoScoreModel=new VideoScoreModel();
        videoScoreModel.setfClasstype(1);//添加电影
        videoScoreModel.setfObjectid(filmModel.getfId());
        //设置分数
        videoScoreModel.setfLanfanqie(filmscore_lanfanqie);
        videoScoreModel.setfImdb(filmscore_imdb);
        videoScoreModel.setfDouban(filmscore_douban);
        Integer res=filmServices.InsertFilm(filmModel,filmInfoModel,videoScoreModel);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
            resultObject.setResult(newid);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;
    }

    @RequestMapping(value = "updatefilm", method = RequestMethod.POST)
    ResultObject<Integer> updatefilm(HttpServletRequest request, @RequestParam String film_name ,
                                    @RequestParam String film_id ,
                                    @RequestParam String film_keyword ,
                                    @RequestParam String film_price ,
                                    @RequestParam Integer film_year ,
                                    @RequestParam Integer film_country ,
                                     @RequestParam String film_showdate,
                                    @RequestParam String film_director ,
                                    @RequestParam String film_performer ,
                                    @RequestParam String film_filmtype ,
                                    @RequestParam String film_desc,
                                    @RequestParam(value = "film_pic",required = false)
                                             MultipartFile film_pic,
                                     @RequestParam(value = "film_pic1",required = false)
                                             MultipartFile film_pic1,
                                     @RequestParam(value = "film_pic2",required = false)
                                             MultipartFile film_pic2) {
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        String path  ="";
        if (film_pic!=null && film_pic.getSize()>0){
            try {
                path = uploadFileUtil.SaveFileByMultiFlie(film_pic,request,UploadFileType.VideoPhoto);
                //path = uploadFileUtil.SaveStreamFile(UploadFileType.Photo, ".jpg", request);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String path1="";
        if (film_pic1!=null && film_pic1.getSize()>0){

            try {
                path1 = uploadFileUtil.SaveFileByMultiFlie(film_pic1,request,UploadFileType.VideoPhoto);
                //path = uploadFileUtil.SaveStreamFile(UploadFileType.Photo, ".jpg", request);
            } catch (Exception e) {
                e.printStackTrace();
                path1="";
            }

        }
        String path2="";
        if (film_pic2!=null && film_pic2.getSize()>0){

            try {
                path2 = uploadFileUtil.SaveFileByMultiFlie(film_pic2,request,UploadFileType.VideoPhoto);
                //path = uploadFileUtil.SaveStreamFile(UploadFileType.Photo, ".jpg", request);
            } catch (Exception e) {
                e.printStackTrace();
                path2="";
            }

        }



        FilmModel filmModel=new FilmModel();
        filmModel.setfId(film_id);
        filmModel.setfName(film_name);
        filmModel.setfKeyword(film_keyword);
        filmModel.setfPricetagid(film_price);
        filmModel.setfCountry(film_country);
        if (film_showdate!=null && film_showdate!=""){
            Date date=com.guanyong.utils.Comm.DateExt.StrToDate2(film_showdate);
            filmModel.setfShowtime(date);
        }

        filmModel.setfYear(film_year);
        filmModel.setfDirector(film_director);
        filmModel.setfPerformer(film_performer);
        filmModel.setfFilmtype(film_filmtype);
        filmModel.setfVideotype(VideoTypeUtils.getViodeType(film_filmtype));
        filmModel.setfKeyword(film_keyword);
        filmModel.setfKeyword(film_keyword);
        if (!path.equals("")){
            filmModel.setfPhoto(path);
        }
        if (!path1.equals("")){
            filmModel.setfPhotow(path1);
        }
        if (!path2.equals("")){
            filmModel.setfPhotos(path2);
        }
        FilmInfoModel filmInfoModel=new FilmInfoModel();
        filmInfoModel.setfId(film_id);
        filmInfoModel.setfIntroduce(film_desc);
        Integer res=filmServices.UpdateFilm(filmModel,filmInfoModel);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;
    }


    @RequestMapping(value = "getTagephotolist", method = RequestMethod.GET)
    ResultObject<String[]> getTagephotolist(HttpServletRequest request,
                                                     @RequestParam String fId ) {
        ResultObject<String[]> result = new ResultObject<String[]>();
        String stagephoto = filmServices.GetFilmInfoModelById(fId).getfStagephoto();
        if (stagephoto!=null &&stagephoto.length()>0){
            String [] temp =stagephoto.split(";");
            result.setResult(temp);
        }
        return result;
    }

    @RequestMapping(value = "addfilmStagephoto", method = RequestMethod.POST)
    ResultObject<Integer> addfilmStagephoto(HttpServletRequest request,
                                     @RequestParam String film_id ,
                                     @RequestParam(value = "film_stagephoto",required = false) MultipartFile film_stagephoto) {
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        String path  =null;

        try {
            path = uploadFileUtil.SaveFileByMultiFlie(film_stagephoto,request,UploadFileType.VideoPhoto);
            System.out.println(path);
        } catch (Exception e) {
            e.printStackTrace();
            resultObject.setCode(ResultCode.OperateFail);
            return  resultObject;
        }


        FilmInfoModel filmInfoModel=filmServices.GetFilmInfoModelById(film_id);
        String fStagephoto = filmInfoModel.getfStagephoto();
        if (!(fStagephoto==null|| "".equals(fStagephoto))){
            fStagephoto=fStagephoto+";"+path;
        }
        Integer res=filmServices.UpdateFilmStagephoto(film_id,fStagephoto);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;
    }


    @RequestMapping(value = "delfilmStagephoto", method = RequestMethod.POST)
    ResultObject<Integer> delfilmStagephoto(HttpServletRequest request,
                                            @RequestParam String film_id ,
                                            @RequestParam String stagephoto) {
        ResultObject<Integer> resultObject=new ResultObject<Integer>();


        FilmInfoModel filmInfoModel=filmServices.GetFilmInfoModelById(film_id);
        String fStagephoto = filmInfoModel.getfStagephoto();
        if (fStagephoto.indexOf(stagephoto)>-1){

            if(fStagephoto.indexOf(stagephoto)==0){
                fStagephoto = fStagephoto.replaceFirst(stagephoto+";", "");
            }else if(fStagephoto.indexOf(stagephoto)>0){
                fStagephoto = fStagephoto.replaceFirst(";"+stagephoto, "");
            }
        }
        Integer res=filmServices.UpdateFilmStagephoto(film_id,fStagephoto);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;
    }



    @RequestMapping(value = "updatefilmscore", method = RequestMethod.POST)
    ResultObject<Double> updatefilmscore(HttpServletRequest request,
                                          @RequestParam Integer filmscore_id ,
                                          @RequestParam Double filmscore_douban ,
                                          @RequestParam Double  filmscore_lanfanqie,
                                          @RequestParam Double  filmscore_imdb){
        ResultObject<Double> resultObject=new ResultObject<Double>();

        VideoScoreModel videoScoreModel=new VideoScoreModel();
        videoScoreModel.setfId(filmscore_id);
        videoScoreModel.setfDouban(filmscore_douban);
        videoScoreModel.setfImdb(filmscore_imdb);
        videoScoreModel.setfLanfanqie(filmscore_lanfanqie);
        String objectid=request.getParameter("filmid");
        //修改分数
        resultObject=videoScoreService.UpdateVideoScore(videoScoreModel,filmServices,objectid);
        return  resultObject;
    }

    @RequestMapping(value = "updatefilmcount", method = RequestMethod.POST)
    ResultObject<Integer> updatefilmcount(HttpServletRequest request,
                                          @RequestParam String  film_id ,
                                          @RequestParam Integer film_makelookct ,
                                          @RequestParam Integer  film_makegoodct,
                                          @RequestParam Integer  film_makecollectct,
                                          @RequestParam Integer  film_makeplayct,
                                          @RequestParam Integer  film_makesharect){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();

        FilmModel filmModel=new FilmModel();
        filmModel.setfId(film_id);
        filmModel.setfMakelookct(film_makelookct);
        filmModel.setfMakegoodct(film_makegoodct);
        filmModel.setfMakecollect(film_makecollectct);
        filmModel.setfPlayct(film_makeplayct);
        filmModel.setfMakesharect(film_makesharect);
        Integer res=filmServices.UpdateFilmSingle(filmModel);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);


        }
        return  resultObject;
    }

    @RequestMapping(value = "getsourcelist", method = RequestMethod.POST)
    ResultObject<List<VideoSourceModel>> getsourcelist(HttpServletRequest request,
                                                       @RequestParam String  objectid ,
                                                       @RequestParam Integer classtype ){
        ResultObject<List<VideoSourceModel>> resultObject=new ResultObject<List<VideoSourceModel>>();
        List<VideoSourceModel> list =videoSourceService.GetVideoScorceByObjectId(classtype, objectid, VideoConstant.SOURCE_SHOW_ALL);
        resultObject.setResult(list);
        return  resultObject;
    }


    @RequestMapping(value = "getsourcebykey", method = RequestMethod.POST)
    ResultObject<VideoSourceModel> getsourcebykey(HttpServletRequest request,
                                                  @RequestParam Integer fid ){
        ResultObject<VideoSourceModel> resultObject=new ResultObject<VideoSourceModel>();
        VideoSourceModel videoSourceModel =videoSourceService.selectByPrimaryKey(fid);
        resultObject.setResult(videoSourceModel);
        return  resultObject;
    }

    @RequestMapping(value = "updateSource", method = RequestMethod.POST)
    ResultObject<Integer> updateSource(HttpServletRequest request,
                                                @RequestParam Integer source_fid ,
                                                @RequestParam String  source_name ,
                                                @RequestParam String  source_url ,
                                                @RequestParam Integer  source_show ){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        VideoSourceModel videoSourceModel = new VideoSourceModel();
        videoSourceModel.setfId(source_fid);
        videoSourceModel.setfSourcename(source_name);
//        videoSourceModel.setfSourceurl(source_url);
        videoSourceModel.setfShow(source_show);
        videoSourceModel.setfSourcetime(new Date());
//        String urlStr = null;
//        try {
//            urlStr = URLEncoder.encode(source_url, "UTF-8");
//            urlStr = urlStr.replaceAll("\\+", "%20");
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        String playAuth =globleData.CDN+urlStr;
//        videoSourceModel.setfSourceurl(playAuth);
        videoSourceModel.setfSourceurl(source_url);


        if("本地".equals(source_name)){
            videoSourceModel.setfSourcetype(0);
        }else if("片花".equals(source_name)){
            videoSourceModel.setfSourcetype(2);
        }else{
            videoSourceModel.setfSourcetype(1);
        }
//        String playAuth ="";
//        try {
////            playAuth =videoLocalUtil.get(source_url);
//            playAuth=source_url;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

//        if (playAuth==null||"".equals(playAuth)){
//            resultObject.setCode(ResultCode.OperateFail);
//            return  resultObject;
//        }
//        videoSourceModel.setfSourceLocal(playAuth);
        videoSourceModel.setfSourceLocal(source_url);
        Integer res=videoSourceService.UpdateVideoSource(videoSourceModel);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;

    }


    @RequestMapping(value = "addSource", method = RequestMethod.POST)
    ResultObject<Integer> addSource(HttpServletRequest request,
                                       @RequestParam String objectid ,
                                       @RequestParam Integer classtype ,
                                       @RequestParam String  source_name ,
                                       @RequestParam String  source_url ,
                                       @RequestParam Integer  source_show ){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        VideoSourceModel videoSourceModel = new VideoSourceModel();
        videoSourceModel.setfObjectid(objectid);
        videoSourceModel.setfClasstype(classtype);
        videoSourceModel.setfSourcename(source_name);
        videoSourceModel.setfShow(source_show);
        videoSourceModel.setfSourcetime(new Date());
        videoSourceModel.setfSourceurl(source_url);
        if("本地".equals(source_name)){
            videoSourceModel.setfSourcetype(0);
        }else if("片花".equals(source_name)){
            videoSourceModel.setfSourcetype(2);
        }else{
            videoSourceModel.setfSourcetype(1);
        }
        videoSourceModel.setfSourceLocal(source_url);
        Integer res=videoSourceService.AddVideoSource(videoSourceModel);
        if (res >-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;

    }




    @RequestMapping(value = "addTopLog", method = RequestMethod.POST)
    ResultObject<Integer> addTopLog(HttpServletRequest request,
                                    @RequestParam String objectid ,
                                    @RequestParam Integer classtype){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        VideoTopLogModel videoTopLogModel = new VideoTopLogModel();
        videoTopLogModel.setfObjectid(objectid);
        videoTopLogModel.setfClasstype(classtype);
        videoTopLogModel.setfIntime( new Date());

        resultObject=videoTopLogService.AddVideoTopLog(videoTopLogModel);
        return  resultObject;

    }


    @RequestMapping(value = "getTopLoglist", method = RequestMethod.POST)
    ResultObject<HashMap<String,Object>> getTopLoglist(HttpServletRequest request,
                                                       @RequestParam Integer classType,
                                                       @RequestParam Integer pno,
                                                       @RequestParam Integer pagesize,
                                                       @RequestParam Integer allcount){
        ResultObject<HashMap<String,Object>> result = new ResultObject<HashMap<String,Object>>();
        HashMap<String,Object> hashMap =videoTopLogService.getVideoTopLogList(classType,pno,pagesize,
                allcount);
        result.setResult(hashMap);
        return  result;
    }

    @RequestMapping(value = "delTopLog", method = RequestMethod.POST)
    ResultObject<Integer>  delTopLog(HttpServletRequest request,
                                                       @RequestParam Integer fid,
                                     @RequestParam Integer classType){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        resultObject=videoTopLogService.delVideoTopLog(fid,classType);
        return  resultObject;
    }

    @RequestMapping(value = "upTopLog", method = RequestMethod.POST)
    ResultObject<Integer>  upTopLog(HttpServletRequest request,
                                     @RequestParam Integer fid,
                                    @RequestParam Integer classType){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        resultObject=videoTopLogService.upVideoTopLog(fid,classType);
        return  resultObject;
    }

    @RequestMapping(value = "addToday", method = RequestMethod.POST)
    ResultObject<Integer> addToday(HttpServletRequest request,
                                    @RequestParam String objectid ,
                                    @RequestParam Integer classtype){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        VideoTodayModel videoTodayModel = new VideoTodayModel();
        videoTodayModel.setfObjectid(objectid);
        videoTodayModel.setfClasstype(classtype);
        videoTodayModel.setfIntime( new Date());
        resultObject=videoTodayService.AddVideoToday(videoTodayModel);
        return  resultObject;

    }


    @RequestMapping(value = "getTodaylist", method = RequestMethod.POST)
    ResultObject<HashMap<String,Object>> getTodaylist(HttpServletRequest request,
                                                       @RequestParam Integer classType,
                                                       @RequestParam Integer pno,
                                                       @RequestParam Integer pagesize,
                                                       @RequestParam Integer allcount){
        ResultObject<HashMap<String,Object>> result = new ResultObject<HashMap<String,Object>>();
        HashMap<String,Object> hashMap =videoTodayService.getVideoTodayList(classType,pno,pagesize,
                allcount);
        result.setResult(hashMap);
        return  result;
    }

    @RequestMapping(value = "delToday", method = RequestMethod.POST)
    ResultObject<Integer>  delToday(HttpServletRequest request,
                                     @RequestParam Integer fid){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        resultObject=videoTodayService.delVideoToday(fid);
        return  resultObject;
    }

    @RequestMapping(value = "upToday", method = RequestMethod.POST)
    ResultObject<Integer>  upToday(HttpServletRequest request,
                                    @RequestParam Integer fid){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        resultObject=videoTodayService.upVideoToday(fid);
        return  resultObject;
    }





    @RequestMapping(value = "getqiniuvideolist", method = RequestMethod.POST)
    ResultObject<Set>  getQiniuList(HttpServletRequest request,
                                        @RequestParam String name){
        ResultObject<Set> resultObject=new ResultObject<Set>();
        //构造一个带指定Zone对象的配置类
        Configuration cfg = new Configuration(Zone.zone0());
//...其他参数参考类注释
        String accessKey = globleData.QiNiu_Ak;
        String secretKey = globleData.Qiniu_SK;
//        String accessKey = globleData.QiNiu_Ak_Test;
//        String secretKey = globleData.Qiniu_SK_Test;
        String bucket = globleData.bucket;
        Auth auth = Auth.create(accessKey, secretKey);
        BucketManager bucketManager = new BucketManager(auth, cfg);
//文件名前缀
        String prefix = name;
        if (name==null||name.length()<2){
            resultObject.setCode(ResultCode.OperateFail);
            resultObject.setErrorMsg("请输入至少2位数据！");
            return  resultObject;
        }
//每次迭代的长度限制，最大1000，推荐值 1000
        int limit = 1000;
//指定目录分隔符，列出所有公共前缀（模拟列出目录效果）。缺省值为空字符串
        String delimiter = "";
//列举空间文件列表
        BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, name, limit, delimiter);
        Set<String> newSet = new HashSet<String>();
        while (fileListIterator.hasNext()) {
            //处理获取的file list结果
            FileInfo[] items = fileListIterator.next();
            for (FileInfo item : items) {
                if(item.key.endsWith(".mp4")){
//                    System.out.println(item.key);
                    newSet.add(item.key);
                }
            }
        }
        resultObject.setResult(newSet);
        return  resultObject;
    }



}
